package sjp.demo.jfinal;

import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import sjp.demo.jfinal.controller.HelloController;

/**
 * Created by vcc on 2017/3/6.
 */
public class DemoConfig extends JFinalConfig {

    //配置JFinal常量值
    @Override
    public void configConstant(Constants me) {
        //设置为开发模式
        me.setDevMode(true);
        //me.setBaseUploadPath();//设置文件下载基础路径

        //设置视图类型
        me.setViewType(ViewType.FREE_MARKER);

        // 添加控制层全局拦截器
        // me.addGlobalActionInterceptor(new GlobalActionInterceptor());
        // 添加业务层全局拦截器
        // me.addGlobalServiceInterceptor(new GlobalServiceInterceptor());



    }

    //配置访问路由
    @Override
    public void configRoute(Routes routes) {
        //finalView = baseViewPath + viewPath + view
        routes.setBaseViewPath("/jfinal");
        routes.add("/hello", HelloController.class);
    }

    //配置模板引擎
    @Override
    public void configEngine(Engine engine) {

    }

    //配置插件
    @Override
    public void configPlugin(Plugins plugins) {
        /*DruidPlugin dp = new DruidPlugin("jdbc:mysql://127.0.0.1:3306/sjp?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8",
                "sjp", "123456");
        plugins.add(dp);

        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        plugins.add(arp);

        arp.addMapping("reply", Reply.class);*/
        //arp.addMapping("article", "article_id", Article.class);
    }

    //配置全局拦截器
    @Override
    public void configInterceptor(Interceptors interceptors) {

    }

    @Override
    public void configHandler(Handlers handlers) {

    }

    public static void main(String[] args) {
        //启动
        JFinal.start("src/main/webapp", 80, "/");
    }

}
